/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.jitclouds.mda;

import br.ufba.lasid.comm.Host;
import br.ufba.lasid.ds.replication.ReplicatedResourceManager;
import br.ufba.lasid.jitclouds.mda.api.JiTReplicationManagerAPI;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author aliriosa
 */
public class JiTReplicationManager extends ReplicatedResourceManager implements JiTReplicationManagerAPI {

    @Override
    public String getName() throws Exception {
        return "JiTReplicationManager";
    }

    @Override
    public void deploy() throws Exception {

        List hosts = JiTContext.getConfiguration().getList("JiTReplicationManager.hosts", new ArrayList());

        for (Object host : hosts) {

            String haddr = (String) host;

            this.register(haddr, Host.isLocalAddress(haddr));

        }

        long period = JiTContext.getConfiguration().getLong("JiTReplicationManager.period", 1000L);

        this.buildup();

        this.setPeriod(period);

        this.startup();
    }

    public static void main(String[] args) throws Exception {
        JiTReplicationManager rm = new JiTReplicationManager();
        rm.deploy();
    }
}
